#include "map.h"
#include "location.h"

Map::Map(int x,int y)
{
    for (int a=0;a<y;a++)
    {
        _locations.push_back( std::vector<Location*>() );
        for (int b=0;b<x;b++)
        {
            _locations[a].push_back(new Location("NA",a,b)); //changed to non-accessible location for easier map-building
        }
    }
}

Map::~Map() {}

void Map::printDMap()
{
    for (int y=0;y<_locations.size();y++)
    {
        for (int x=0;x<_locations[y].size();x++)
        {
            std::cout << _locations[y][x]->DS ;
        }
        std::cout << std::endl;
    }
}

/*
     Assigns a location to the map.
 */
void Map::Insert(Location *loc)
{
    // Out of bounds check.
    if (loc->GetX()<_locations[0].size() && loc->GetY()<_locations.size())
    {
        _locations[loc->GetY()][loc->GetX()] = loc;
    }
}

/*
    Returns a pointer to the Location given
    the x and y coordinates.

    NULL if out of bounds.
 */
Location* Map::GetLocation(int x,int y)
{
    //Bounds check.
    if (x<60 && y<60 and
        x > -1 && y > -1) //changed due to crashing in program
    {
        return _locations[y][x];
    }
    return (Location*)NULL;
}

bool Map::checkLocation(int x, int y) //chris change
{
    Location* checking = GetLocation(x,y);
    if (checking == NULL)
        return false;
    else
    {
        if(checking->getName() == "NA")
            return false;
    }
    return true;
}
